import request from '@/utils/request';
import URLS from './APIUrlDefine';
import {CURRENT_TOKEN} from '@/components/Authorized/renderAuthorize';
import {message} from "antd";

// import { reject } from 'lodash';


export async function GetCourseList(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_LIST}/${data.current}/${data.pageSize}?type=0&state=${data.state}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetCourseListInfo(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_LIST_INFO}/${data.current}/${data.pageSize}?type=0&state=${data.state}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}


export async function GetTemplateList(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_TEMPLATE_LIST}/${data.current}/${data.pageSize}?type=0`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    // console.log(data)
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch((e) => {
    console.log(e);
  });
}

export async function CreateNewCourse(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_COURSE, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateCourse(data: any): Promise<any> {
  return request(URLS.UPDATE_COURSE, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function ChangeCourseState(data: any): Promise<any> {
  return request(`${URLS.CHANGE_COURSE_STATE}/${data.id}/${data.state}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function DeleteCourse(data: any): Promise<any> {
  return request(`${URLS.DELETE_COURSE}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

//课程审核失败
export async function RejectCourse(data: any): Promise<any> {
  return request(`${URLS.POST_REJECT_COURSE}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

//课程审核通过
export async function PassCourse(data: any): Promise<any> {
  return request(`${URLS.POST_PASS_COURSE}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

//提交课程到审核
export async function SubmitCourse(data: any): Promise<any> {
  return request(`${URLS.POST_SUBMIT_COURSE}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

//取消审核
export async function CancelCourse(data: any): Promise<any> {
  return request(`${URLS.POST_CANCEL_COURSE}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

//课程发布上线
export async function PublishCourse(data: any): Promise<any> {
  return request(`${URLS.POST_PUBLISH_COURSE}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

//拉取课程评论
export async function GetCourseComment(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_COMMENT}/${data.page}/${data.pageSize}?id=${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function SearchGetCourseList(keyword: string) {
  return request(`${URLS.SEARCH_COURSE}?key=${keyword}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetCourseDetail(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_DETAIL}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

/*
export async function GetTeacherList(data: any): Promise<any> {
    return request(`${URLS.GET_COURSE_TEACHER_LIST}/${data.id}`, {
        method: 'GET',
        headers: {
            Authorization: `Bearer ${CURRENT_TOKEN}`,
        },
    }).then((response) => {
        const data = response.data
        return Promise.resolve(data);
    }).catch(e=>{console.error(e)});
}*/

export async function GetAllTeachers(data: any): Promise<any> {
  return request(`${URLS.GET_TEACHER_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}

/*export async function CreateNewTeacher(data: any): Promise<any> {
    return request(URLS.CREATE_NEW_COURSE_TEACHER, {
        method: 'POST',
        headers: {
            Authorization: `Bearer ${CURRENT_TOKEN}`,
            'content-type': 'application/json',
        },
        data: JSON.stringify(data)
    }).catch(e=>{console.error(e)});
}*/

/*export async function DeleteTeacher(data: any): Promise<any> {
    return request(`${URLS.DELETE_COURSE_TEACHER}/${data.id}`, {
        method: 'DELETE',
        headers: {
            Authorization: `Bearer ${CURRENT_TOKEN}`,
            'content-type': 'application/json',
        },
        params: data
    }).catch(e=>{console.error(e)});
}*/

export async function SearchGetModeList(keyword: string) {
  return request(`${URLS.SEARCH_COURSE_MODE}?key=${keyword}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetAssetsList(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_ASSETS_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateNewAssets(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_COURSE_ASSETS, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function ChangeAssetsState(data: any): Promise<any> {
  return request(`${URLS.CHANGE_COURSE_ASSETS_STATE}/${data.id}/${data.state}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function DeleteAssets(data: any): Promise<any> {
  return request(`${URLS.DELETE_COURSE_ASSETS}/${data.id}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function SearchGetAssets(keyword: string) {
  return request(`${URLS.SEARCH_COURSE_ASSETS}?key=${keyword}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetChapterList(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_CHAPTER_LIST}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateNewChapter(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_COURSE_CHAPTER, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function DeleteChapter(data: any): Promise<any> {
  return request(`${URLS.DELETE_COURSE_CHAPTER}/${data.id}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function GetChapterDetail(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_CHAPTER_DETAIL}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateChapter(data: any): Promise<any> {
  return request(URLS.UPDATE_COURSE_CHAPTER, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

/*修改课程设计*/
export async function UpdateCourseDesign(data: any): Promise<any> {
  return request(URLS.UPDATE_COURSE_DESIGN, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

/*修改考核标准*/
export async function UpdateExamStandard(data: any): Promise<any> {
  return request(URLS.UPDATE_EXAM_STANDARD, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateNewChapterCourseArticle(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_CHAPTER_COURSE_ARTICLE, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateChapterCourseArticle(data: any): Promise<any> {
  return request(URLS.UPDATE_CHAPTER_COURSE_ARTICLE, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateNewChapterCourseVideo(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_CHAPTER_COURSE_VIDEO, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateChapterCourseVideo(data: any): Promise<any> {
  return request(URLS.UPDATE_CHAPTER_COURSE_VIDEO, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateNewChapterCourseVR(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_CHAPTER_COURSE_VR, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateChapterCourseVR(data: any): Promise<any> {
  return request(URLS.UPDATE_CHAPTER_COURSE_VR, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateNewChapterCourseLiving(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_CHAPTER_COURSE_LIVING, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function MoveChapter(data: any): Promise<any> {
  return request(`${URLS.MOVE_CHAPER_ORDER}/${data.chapterId}?dir=${data.dir}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateChapterCourseLiving(data: any): Promise<any> {
  return request(URLS.UPDATE_CHAPTER_COURSE_LIVING, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  });
}

export async function GetTypeList(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_TYPE_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}

export async function ChangeTypeState(data: any): Promise<any> {
  return request(`${URLS.CHANGE_COURSE_TYPE_STATE}/${data.id}/${data.state}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateNewType(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_COURSE_TYPE, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).then((resp) => {
      if (resp.code === 10000) {
        return Promise.resolve(resp);
      } else {
        message.error(resp.msg);
        return Promise.reject();
      }
    }
  );
}

export async function UpdateType(data: any): Promise<any> {
  return request(URLS.UPDATE_COURSE_TYPE, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function DeleteType(data: any): Promise<any> {
  return request(`${URLS.DELETE_COURSE_TYPE}/${data.id}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function SearchGetTypeList(keyword: string) {
  return request(`${URLS.SEARCH_COURSE_TYPE}?key=${keyword}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetTagList(data: any): Promise<any> {
  return request(`${URLS.GET_TAG_LIST}/${data.current}/${data.pageSize}?type=1`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}

export async function ChangeTagState(data: any): Promise<any> {
  return request(`${URLS.CHANGE_TAG_STATE}/${data.id}/${data.state}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateNewTag(data: any): Promise<any> {
  return request(URLS.CREATE_NEW_TAG, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateTag(data: any): Promise<any> {
  return request(URLS.UPDATE_TAG, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).catch(e => {
    console.error(e)
  });
}

export async function DeleteTag(data: any): Promise<any> {
  return request(`${URLS.DELETE_TAG}/${data.id}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data
  }).catch(e => {
    console.error(e)
  });
}

export async function SearchGetTagList(keyword: string) {
  return request(`${URLS.SEARCH_TAG}?key=${keyword}&type=1`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

/**
 * 获取公告列表
 * @param data
 */
export async function GetNoticeList(data: any): Promise<any> {
  return request(`${URLS.GET_COURSE_NOTICE}/${data.current}/${data.pageSize}?courseId=${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}

/**
 * 创建公告
 */

export async function CreateNotice(data: any): Promise<any> {
  return request(`${URLS.CREATE_COURSE_NOTICE}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function CreateCourseMember(data: any) {
  return request(`${URLS.CREATE_NEW_COURSE_MEMBER}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetCourseMemberList(data: any) {
  // console.log(data.courseId)
  return request(`${URLS.GET_COURSE_MEMBER_LIST}/${data.current}/${data.pageSize}?courseId=${data.courseId}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    // const result =  data? data.records:[]
    // console.log(result)
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetAllCourseMember(data: any) {
  return request(`${URLS.USER_GET_COURSE_MEMBER_ALL}/${data.courseId}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;

    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateCourseMember(data: any) {
  return request(`${URLS.UPDATE_COURSE_MEMBER}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function DeleteCourseMember(id: number) {
  return request(`${URLS.DELETE_COURSE_MEMBER}/${id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function ChangeCourseMemberState(data: any) {
  return request(`${URLS.CHANGE_COURSE_MEMBER_STATE}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}


export async function CreateVRLessonDoc(data: any) {
  return request(`${URLS.CREATE_NEW_VR_LESSON_DOC}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetVRLessonDocList(data: any) {
  return request(`${URLS.GET_VR_LESSON_DOC_LIST}/${data.current}/${data.pageSize}?lessonId=${data.lessonId}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  }).catch(e => {
    console.error(e)
  });
}

export async function UpdateVRLessonDoc(data: any) {
  return request(`${URLS.UPDATE_VR_LESSON_DOC}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function DeleteVRLessonDoc(id: number) {
  return request(`${URLS.DELETE_VR_LESSON_DOC}/${id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

export async function ChangeVRLessonDocState(data: any) {
  return request(`${URLS.CHANGE_VR_LESSON_DOC_STATE}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data)
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  });
}
